package com.zzy.demo.web;

import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.GetMapping;

import com.zzy.demo.common.constant.SysConstant;
import com.zzy.demo.utils.validate.code.ImageCode;
import com.zzy.demo.utils.validate.code.ImageCodeGenerator;

/**
 * 
 * @author kevin
 *
 */
@Controller
public class ValidateCodeController {

   
    
    

    @GetMapping("/code/image")
    public void imageCode(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletRequestBindingException {
        ImageCode imageCode=ImageCodeGenerator.generate(request);
        		
        request.getSession().setAttribute(SysConstant.SESSION_KEY, imageCode);
        
        ImageIO.write(imageCode.getImage(), "JPEG", response.getOutputStream());
    }


}
